﻿using System;
using System.IO;
using System.Windows.Forms;
using ProxyMA.Properties;

namespace ProxyMA
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainFormLoad(object sender, EventArgs e)
        {
            var apps = Settings.Default.Apps.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
            var startup = Settings.Default.Startup.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var app in apps)
            {
                appToolStripMenuItem.DropDownItems.Add(new ToolStripMenuItem(app, null, AppToolStripMenuItem_OnClick));
                if (!File.Exists(app)) continue;
            }

            foreach (string s in startup)
            {
                string app = apps[int.Parse(s)];
                var proxyForm = new ProxyForm(app)
                {
                    MdiParent = this,
                    Text = app
                };
                proxyForm.Start();
            }
        }

        private void AppToolStripMenuItem_OnClick(object sender, EventArgs e)
        {
            string app = ((ToolStripMenuItem)sender).Text;
            var proxyForm = new ProxyForm(app)
            {
                MdiParent = this,
                Text = app
            };
            proxyForm.Start();
        }
    }
}